package cn.com.dycc.meeting_assist.meeting_summary.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.meeting_assist.meeting_summary.entity.Summary;
import cn.com.dycc.meeting_assist.meeting_summary.param.FindSummaryParam;
import cn.com.dycc.meeting_assist.meeting_summary.param.SummaryParam;
import cn.com.dycc.meeting_assist.meeting_summary.service.SummaryNotFoundException;
import cn.com.dycc.meeting_assist.meeting_summary.service.SummaryService;
import cn.com.dycc.util.JsonObjectResult;


/**
 * 
 * Description: 会议纪要管理控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年10月29日 下午3:54:20.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/summary")
public class SummaryController extends BaseController{
	
	@Resource
	private SummaryService summaryService;
	
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addSummary(HttpServletRequest req,Summary summary){
		int n = summaryService.addSummary(req, summary);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteSummary(HttpServletRequest req,String meeting_id){
		int n = summaryService.deleteSummary(req, meeting_id);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updateSummary(HttpServletRequest req,Summary summary){
		int n = summaryService.updateSummary(req, summary);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findSummary(HttpServletRequest req,String meeting_id){
		SummaryParam summary = summaryService.findSummaryById(req, meeting_id);
		return new JsonObjectResult(summary);
	}
	
	@RequestMapping("/param.do")
	@ResponseBody
	public JsonObjectResult paramSummary(HttpServletRequest req,FindSummaryParam param){
		List<SummaryParam> list = summaryService.findSummaryByParam(req, param);
		String count = summaryService.countSummaryByParam(req, param);
		return new JsonObjectResult(count,list);
	}
	
	@ExceptionHandler(SummaryNotFoundException.class)
	@ResponseBody
	public JsonObjectResult summaryException(SummaryNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(1013,e);
	}
}
